<template>
    <div class="login">
        <div class="container">
            <a href="/#/index">
                <img src="~@/public/imgs/login-logo.png" alt="">
            </a>
        </div>
        <div class="wrapper">
            <div class="container">
                <div class="login-form">
                    <h3>
                        <span>账号登录</span>
                        <span>|</span>
                        <span>扫码登录</span>
                    </h3>
                    <div class="input">
                        <input type="text" placeholder="请输入账号" v-model="username">
                    </div>
                    <div class="input">
                        <input type="text" placeholder="请输入密码" v-model="password">
                    </div>
                    <div class="btn-box">
                        <a href="javascript:;" class="btn" v-on:click="login">登录</a>
                    </div>
                    <div class="tips">
                        <div class="sms" @click="register">手机短信登录\注册</div>
                    </div>
                </div>
            </div>
        </div>
        <login-footer></login-footer>
    </div>
</template>

<script>
    import LoginFooter from "./childComponent/LoginFooter"

    export default {
        name: "Login",
        data() {
            return {
                username: '',
                password: '',
                userId: '',
            }
        },
        components: {
            LoginFooter,
        },
        methods: {
            //登录
            login() {
                let {username, password} = this;
                this.$post('/api/user/login', {
                    username,
                    password
                }).then(res => {
                    //vue-ccokie的使用
                    console.log(res);
                    this.$cookie.set('userId', res.id, {expires: '1M'});
                    //to-do 保存用户名
                    this.$store.dispatch('saveUserName', res.username);
                    this.$router.push('/index');
                });
            },
            //注册
            register() {
                this.$post('/api/user/register', {
                    username: 'jason123',
                    password: 'jason123',
                    email: 'jason123456@163.com',
                }).then(res => {
                    alert("注册成功");
                    console.log(res);
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    @import "~@/assets/scss/mixin.scss";
    @import "~@/assets/scss/base.scss";

    .login {
        .container {
            width: 1226px;
            height: 113px;
            margin: 0 auto;

            a {
                display: inline-block;
                height: 100%;

                img {
                    vertical-align: middle;
                    height: 100%;
                }
            }
        }

        .wrapper {
            background: url('~@/public/imgs/login-bg.jpg') no-repeat center;

            .container {
                height: 576px;
                position: relative;

                .login-form {
                    width: 410px;
                    height: 510px;
                    padding: 0 31px;
                    box-sizing: border-box;
                    background-color: #fff;
                    position: absolute;
                    right: 0;
                    bottom: 29px;

                    h3 {
                        line-height: 23px;
                        font-size: 24px;
                        text-align: center;
                        margin: 40px auto 49px;

                        span {
                            &:first-child {
                                color: #f60;
                            }

                            &:nth-child(2) {
                                margin: 0 32px;
                            }
                        }
                    }

                    .input {
                        width: 348px;
                        height: 50px;
                        border: 1px solid #e5e5e5;
                        margin-bottom: 20px;

                        input {
                            box-sizing: border-box;
                            width: 100%;
                            height: 100%;
                            border: none;
                            padding: 18px;
                            font-size: 14px;
                        }
                    }

                    .btn-box {
                        .btn {
                            width: 100%;
                            line-height: 50px;
                            margin-top: 10px;
                            font-size: 16px;
                        }
                    }

                    .tips {
                        margin-top: 14px;
                        display: flex;
                        justify-content: space-between;
                        cursor: pointer;

                        .sms {
                            color: #f60;
                        }
                    }
                }
            }
        }
    }
</style>
